<template>
  <div id="app">
    <router-view></router-view>
    <van-tabbar
      v-if="sisuiXianShi"
      route
      fixed
      active-color="red"
      inactive-color="#000"
    >
      <van-tabbar-item replace to="/home" icon="wap-home-o"
        >首页</van-tabbar-item
      >
      <van-tabbar-item replace to="/zhuan" icon="description"
        >专题</van-tabbar-item
      >
      <van-tabbar-item replace to="/fen" icon="apps-o">分类</van-tabbar-item>
      <van-tabbar-item replace to="/cart" icon="cart-o">购物车</van-tabbar-item>
      <van-tabbar-item replace to="/my" icon="friends-o">我的</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      sisuiXianShi: true,
    };
  },
  watch: {
    $route(to, from) {
      // console.log(to, from);
      let path = ["/home", "/fen", "/zhuan", "/cart", "/my"];
      let sisui = path.find((el) => el == to.path);
      if (sisui) {
        this.sisuiXianShi = true;
      } else {
        this.sisuiXianShi = false;
      }
    },
  },
  created() {
    // 往本地存储登录信息
    var userInfo = {
      openId: "1315570",

      nickName: "四岁",

      avatarUrl:
        "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIbWFEIJj8IpGeHM7dGic1aTFZALjWcMm9ltWfFiaQfVRYticWBfgGfzXWMt2EkJWiaicPtftHAlWxUibxQ/132",
    };

    var openId = userInfo.openId;

    localStorage.setItem("userInfo", JSON.stringify(userInfo));

    localStorage.setItem("openId", openId);
  },
};
</script>

<style lang="less">
* {
  margin: 0;
  padding: 0;
}
html,
body,
#app {
  height: 100vh;
  background-color: rgb(250, 249, 249);
}
</style>
